<template>
  <div class="page">
    <h2>输入 Git 仓库链接</h2>
    <el-input v-model="gitLink" placeholder="请输入 Git 仓库 URL" clearable></el-input>
    <el-button type="primary" @click="submitLink" :loading="loading">
      <span v-if="!loading">提交</span>
      <span v-else>加载中...</span>
    </el-button>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';
import { useGitStore } from '@/stores/gitStore';

export default defineComponent({
  setup() {
    const gitLink = ref('');
    const loading = ref(false);
    const gitStore = useGitStore();

    const submitLink = async () => {
      loading.value = true;
      try {
        await gitStore.fetchGitData(gitLink.value);
        // 下载逻辑可以放在这里，例如弹出一个下载框
      } catch (error) {
        console.error('Error fetching Git data:', error);
      } finally {
        loading.value = false;
      }
    };

    return {
      gitLink,
      loading,
      submitLink,
    };
  },
});
</script>

<style scoped>
.page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px;
  background-color: #f9f9f9; /* 增加背景色 */
  border-radius: 8px; /* 添加圆角效果 */
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* 添加阴影效果 */
}

h2 {
  margin-bottom: 20px;
  font-size: 1.8rem;
  color: #333; /* 改善字体颜色 */
}

.el-input {
  width: 100%;
  max-width: 400px;
  margin-bottom: 20px;
}

.el-button {
  width: 100%;
  max-width: 150px;
}

.el-button[type="primary"] {
  background-color: #337ab7;
  border-color: #337ab7;
  color: #fff;
}

.el-button[type="primary"]:hover {
  background-color: #285e8e;
  border-color: #285e8e;
}
</style>